<!DOCTYPE html SYSTEM "about:legacy-compat">
<html lang="en"><head><META http-equiv="Content-Type" content="text/html; charset=UTF-8"><link href="./images/docs-stylesheet.css" rel="stylesheet" type="text/css"><title>Apache Tomcat 8 (8.5.31) - Windows service HOW-TO</title><meta name="author" content="Mladen Turk"><script type="application/javascript" data-comments-identifier="tomcat-8.5-doc/windows-service-howto">
    "use strict"; // Enable strict mode

    (function() {
      var thisScript = document.currentScript;
      if (!thisScript) { // Workaround for IE <= 11
        var scripts = document.getElementsByTagName("script");
        thisScript = scripts[scripts.length - 1];
      }
      document.addEventListener("DOMContentLoaded", (function() {
        var commentsDiv = document.getElementById("comments_thread");
        var commentsShortname = "tomcat";
        var commentsIdentifier = "http://tomcat.apache.org/" +
          thisScript.getAttribute("data-comments-identifier") + ".html";

        (function(w, d) {
          if (w.location.hostname.toLowerCase() == "tomcat.apache.org") {
            var s = d.createElement("script");
            s.type = "application/javascript";
            s.async = true;
            s.src = "https://comments.apache.org/show_comments.lua?site=" +
              encodeURIComponent(commentsShortname) +
              "&page=" + encodeURIComponent(commentsIdentifier);
            d.head.appendChild(s);
          } else {
            commentsDiv.appendChild(d.createTextNode("Comments are disabled for this page at the moment."));
          }
        })(window, document);
      }), false);
    })();
  </script></head><body><div id="wrapper"><header><div id="header"><div><div><div class="logo noPrint"><a href="http://tomcat.apache.org/"><img alt="Tomcat Home" src="./images/tomcat.png"></a></div><div style="height: 1px;"></div><div class="asfLogo noPrint"><a href="http://www.apache.org/" target="_blank"><img src="./images/asf-logo.svg" alt="The Apache Software Foundation" style="width: 266px; height: 83px;"></a></div><h1>Apache Tomcat 8</h1><div class="versionInfo">
          Version 8.5.31,
          <time datetime="2018-04-27">Apr 27 2018</time></div><div style="height: 1px;"></div><div style="clear: left;"></div></div></div></div></header><div id="middle"><div><div id="mainLeft" class="noprint"><div><nav><div><h2>Links</h2><ul><li><a href="index.html">Docs Home</a></li><li><a href="http://wiki.apache.org/tomcat/FAQ">FAQ</a></li><li><a href="#comments_section">User Comments</a></li></ul></div><div><h2>User Guide</h2><ul><li><a href="introduction.html">1) Introduction</a></li><li><a href="setup.html">2) Setup</a></li><li><a href="appdev/index.html">3) First webapp</a></li><li><a href="deployer-howto.html">4) Deployer</a></li><li><a href="manager-howto.html">5) Manager</a></li><li><a href="host-manager-howto.html">6) Host Manager</a></li><li><a href="realm-howto.html">7) Realms and AAA</a></li><li><a href="security-manager-howto.html">8) Security Manager</a></li><li><a href="jndi-resources-howto.html">9) JNDI Resources</a></li><li><a href="jndi-datasource-examples-howto.html">10) JDBC DataSources</a></li><li><a href="class-loader-howto.html">11) Classloading</a></li><li><a href="jasper-howto.html">12) JSPs</a></li><li><a href="ssl-howto.html">13) SSL/TLS</a></li><li><a href="ssi-howto.html">14) SSI</a></li><li><a href="cgi-howto.html">15) CGI</a></li><li><a href="proxy-howto.html">16) Proxy Support</a></li><li><a href="mbeans-descriptors-howto.html">17) MBeans Descriptors</a></li><li><a href="default-servlet.html">18) Default Servlet</a></li><li><a href="cluster-howto.html">19) Clustering</a></li><li><a href="balancer-howto.html">20) Load Balancer</a></li><li><a href="connectors.html">21) Connectors</a></li><li><a href="monitoring.html">22) Monitoring and Management</a></li><li><a href="logging.html">23) Logging</a></li><li><a href="apr.html">24) APR/Native</a></li><li><a href="virtual-hosting-howto.html">25) Virtual Hosting</a></li><li><a href="aio.html">26) Advanced IO</a></li><li><a href="extras.html">27) Additional Components</a></li><li><a href="maven-jars.html">28) Mavenized</a></li><li><a href="security-howto.html">29) Security Considerations</a></li><li><a href="windows-service-howto.html">30) Windows Service</a></li><li><a href="windows-auth-howto.html">31) Windows Authentication</a></li><li><a href="jdbc-pool.html">32) Tomcat's JDBC Pool</a></li><li><a href="web-socket-howto.html">33) WebSocket</a></li><li><a href="rewrite.html">34) Rewrite</a></li></ul></div><div><h2>Reference</h2><ul><li><a href="RELEASE-NOTES.txt">Release Notes</a></li><li><a href="config/index.html">Configuration</a></li><li><a href="api/index.html">Tomcat Javadocs</a></li><li><a href="servletapi/index.html">Servlet Javadocs</a></li><li><a href="jspapi/index.html">JSP 2.3 Javadocs</a></li><li><a href="elapi/index.html">EL 3.0 Javadocs</a></li><li><a href="websocketapi/index.html">WebSocket 1.1 Javadocs</a></li><li><a href="http://tomcat.apache.org/connectors-doc/">JK 1.2 Documentation</a></li></ul></div><div><h2>Apache Tomcat Development</h2><ul><li><a href="building.html">Building</a></li><li><a href="changelog.html">Changelog</a></li><li><a href="http://wiki.apache.org/tomcat/TomcatVersions">Status</a></li><li><a href="developers.html">Developers</a></li><li><a href="architecture/index.html">Architecture</a></li><li><a href="funcspecs/index.html">Functional Specs.</a></li><li><a href="tribes/introduction.html">Tribes</a></li></ul></div></nav></div></div><div id="mainRight"><div id="content"><h2>Windows service HOW-TO</h2><h3 id="Table_of_Contents">Table of Contents</h3><div class="text">
<ul><li><a href="#Tomcat_service_application">Tomcat service application</a></li><li><a href="#Tomcat_monitor_application">Tomcat monitor application</a></li><li><a href="#Command_line_arguments">Command line arguments</a></li><li><a href="#Command_line_parameters">Command line parameters</a></li><li><a href="#Installing_services">Installing services</a></li><li><a href="#Updating_services">Updating services</a></li><li><a href="#Removing_services">Removing services</a></li><li><a href="#Debugging_services">Debugging services</a></li><li><a href="#Multiple_Instances">Multiple Instances</a></li></ul>
</div><h3 id="Tomcat_service_application">Tomcat service application</h3><div class="text">
<p>
    <b>Tomcat8</b> is a service application for running Tomcat
    8 as a Windows service.
</p>
</div><h3 id="Tomcat_monitor_application">Tomcat monitor application</h3><div class="text">
<p>
    <b>Tomcat8w</b> is a GUI application for monitoring and
    configuring Tomcat services.
</p>
    <p>The available command line options are:</p>

    <table class="defaultTable">
    <tr><td><b>//ES//</b></td>
        <td>Edit service configuration</td>
        <td>This is the default operation. It is called if the no option is
            provided but the executable is renamed to <b>servicenameW.exe</b></td>
    </tr>
    <tr><td><b>//MS//</b></td>
        <td>Monitor service</td>
        <td>Put the icon in the system tray</td>
    </tr>
    </table>

</div><h3 id="Command_line_arguments">Command line arguments</h3><div class="text">
<p>
    Each command line directive is in the form of <b>//XX//ServiceName</b>
</p>
    <p>The available command line options are:</p>

    <table class="defaultTable">
    <tr><td><b>//TS//</b></td>
        <td>Run the service as console application</td>
        <td>This is the default operation. It is called if the no option is
            provided. The ServiceName is the name of the executable without
            exe suffix, meaning Tomcat8</td>
    </tr>
    <tr><td><b>//RS//</b></td>
        <td>Run the service</td>
        <td>Called only from ServiceManager</td>
    </tr>
    <tr><td><b>//SS//</b></td>
        <td>Stop the service</td>
        <td></td>
    </tr>
    <tr><td><b>//US//</b></td>
        <td>Update service parameters</td>
        <td></td>
    </tr>
    <tr><td><b>//IS//</b></td>
        <td>Install service</td>
        <td></td>
    </tr>
    <tr><td><b>//DS//</b></td>
        <td>Delete service</td>
        <td>Stops the service if running</td>
    </tr>
    </table>

</div><h3 id="Command_line_parameters">Command line parameters</h3><div class="text">
<p>
    Each command line parameter is prefixed with <b>--</b>. If the command line
    parameter is prefixed with <b>++</b> then it's value will be appended to the
    existing option.
    If the environment variable with the same name as command line parameter but
    prefixed with <code>PR_</code> exists it will take precedence.
    For example:</p>
<div class="codeBox"><pre><code>set PR_CLASSPATH=xx.jar</code></pre></div>

<p>is equivalent to providing</p>
<div class="codeBox"><pre><code>--Classpath=xx.jar</code></pre></div>
<p> as command line parameter.</p>

    <table class="defaultTable">
    <tr>
    <th>ParameterName</th>
    <th>Default</th>
    <th>Description</th>
    </tr>
    <tr>
    <td>--Description</td>
    <td></td>
    <td>Service name description (maximum 1024 characters)</td>
    </tr>
    <tr>
    <td>--DisplayName</td>
    <td>ServiceName</td>
    <td>Service display name</td>
    </tr>
    <tr>
    <td>--Install</td>
    <td>procrun.exe //RS//ServiceName</td>
    <td>Install image</td>
    </tr>
    <tr>
    <td>--Startup</td>
    <td>manual</td>
    <td>Service startup mode can be either <b>auto</b> or <b>manual</b></td>
    </tr>
    <tr>
    <td>--DependsOn</td>
    <td></td>
    <td>List of services that this service depend on. Dependent services
        are separated using either <b>#</b> or <b>;</b> characters</td>
    </tr>
    <tr>
    <td>--Environment</td>
    <td></td>
    <td>List of environment variables that will be provided to the service
        in the form <b>key=value</b>. They are separated using either
        <b>#</b> or <b>;</b> characters. If you need to use either the <b>#</b>
        or <b>;</b> character within a value then the entire value must be
        enclosed inside single quotes.</td>
    </tr>
    <tr>
    <td>--User</td>
    <td></td>
    <td>User account used for running executable. It is used only for
        StartMode <b>java</b> or <b>exe</b> and enables running applications
        as service under account without LogonAsService privilege.</td>
    </tr>
    <tr>
    <td>--Password</td>
    <td></td>
    <td>Password for user account set by --User parameter</td>
    </tr>
    <tr>
    <td>--JavaHome</td>
    <td>JAVA_HOME</td>
    <td>Set a different JAVA_HOME than defined by JAVA_HOME environment
        variable</td>
    </tr>
    <tr>
    <td>--Jvm</td>
    <td>auto</td>
    <td>Use either <b>auto</b> (i.e. find the JVM from the Windows registry)
        or specify the full path to the <b>jvm.dll</b>.
        You can use the environment variable expansion here.</td>
    </tr>
    <tr>
    <td>--JvmOptions</td>
    <td>-Xrs</td>
    <td>List of options in the form of <b>-D</b> or <b>-X</b> that will be
        passed to the JVM. The options are separated using either
        <b>#</b> or <b>;</b> characters. If you need to embed either <b>#</b> or
        <b>;</b> characters, put them inside single quotes. (Not used in
        <b>exe</b> mode.)</td>
    </tr>
    <tr>
    <td>--JvmOptions9</td>
    <td></td>
    <td>List of options in the form of <b>-D</b> or <b>-X</b> that will be
        passed to the JVM when running on Java 9 or later. The options are
        separated using either <b>#</b> or <b>;</b> characters. If you need to
        embed either <b>#</b> or <b>;</b> characters, put them inside single
        quotes. (Not used in <b>exe</b> mode.)</td>
    </tr>
    <tr>
    <td>--Classpath</td>
    <td></td>
    <td>Set the Java classpath. (Not used in <b>exe</b> mode.)</td>
    </tr>
    <tr>
    <td>--JvmMs</td>
    <td></td>
    <td>Initial memory pool size in MB. (Not used in <b>exe</b> mode.)</td>
    </tr>
    <tr>
    <td>--JvmMx</td>
    <td></td>
    <td>Maximum memory pool size in MB. (Not used in <b>exe</b> mode.)</td>
    </tr>
    <tr>
    <td>--JvmSs</td>
    <td></td>
    <td>Thread stack size in KB. (Not used in <b>exe</b> mode.)</td>
    </tr>
    <tr>
    <td>--StartMode</td>
    <td></td>
    <td>One of <b>jvm</b>, <b>Java</b> or <b>exe</b>. The modes are:
      <ul>
        <li>jvm - start Java in-process. Depends on jvm.dll, see <b>--Jvm</b>.</li>
        <li>Java - same as exe, but automatically uses the default Java
         executable, i.e. %JAVA_HOME%\bin\java.exe. Make sure JAVA_HOME is set
         correctly, or use --JavaHome to provide the correct location.
         If neither is set, procrun will try to find the default JDK (not JRE)
         from the Windows registry.</li>
        <li>exe - run the image as a separate process</li>
      </ul>
    </td>
    </tr>
    <tr>
    <td>--StartImage</td>
    <td></td>
    <td>Executable that will be run. Only applies to <b>exe</b> mode.</td>
    </tr>
    <tr>
    <td>--StartPath</td>
    <td></td>
    <td>Working path for the start image executable.</td>
    </tr>
    <tr>
    <td>--StartClass</td>
    <td>Main</td>
    <td>Class that contains the startup method. Applies to the <b>jvm</b> and
        <b>Java</b> modes. (Not used in <b>exe</b> mode.) </td>
    </tr>
    <tr>
    <td>--StartMethod</td>
    <td>main</td>
    <td>Method name if differs then main</td>
    </tr>
    <tr>
    <td>--StartParams</td>
    <td></td>
    <td>List of parameters that will be passed to either StartImage or
        StartClass. Parameters are separated using either <b>#</b> or
        <b>;</b> character.</td>
    </tr>
    <tr>
    <td>--StopMode</td>
    <td></td>
    <td>One of <b>jvm</b>, <b>Java</b> or <b>exe</b>. See <b>--StartMode</b>
        for further details. </td>
    </tr>
    <tr>
    <td>--StopImage</td>
    <td></td>
    <td>Executable that will be run on Stop service signal. Only applies to
        <b>exe</b> mode.</td>
    </tr>
    <tr>
    <td>--StopPath</td>
    <td></td>
    <td>Working path for the stop image executable. Does not apply to <b>jvm</b>
        mode.</td>
    </tr>
    <tr>
    <td>--StopClass</td>
    <td>Main</td>
    <td>Class that will be used on Stop service signal. Applies to the
        <b>jvm</b> and <b>Java</b> modes. </td>
    </tr>
    <tr>
    <td>--StopMethod</td>
    <td>main</td>
    <td>Method name if differs then main</td>
    </tr>
    <tr>
    <td>--StopParams</td>
    <td></td>
    <td>List of parameters that will be passed to either StopImage or
        StopClass. Parameters are separated using either <b>#</b> or
        <b>;</b> character.</td>
    </tr>
    <tr>
    <td>--StopTimeout</td>
    <td>No Timeout</td>
    <td>Defines the timeout in seconds that procrun waits for service to
        exit gracefully.</td>
    </tr>
    <tr>
    <td>--LogPath</td>
    <td>%SystemRoot%\System32\LogFiles\Apache</td>
    <td>Defines the path for logging. Creates the directory if necessary.</td>
    </tr>
    <tr>
    <td>--LogPrefix</td>
    <td>commons-daemon</td>
    <td>Defines the service log filename prefix. The log file is created in the
        LogPath directory with <code>.YEAR-MONTH-DAY.log</code> suffix</td>
    </tr>
    <tr>
    <td>--LogLevel</td>
    <td>Info</td>
    <td>Defines the logging level and can be either <b>Error</b>,
        <b>Info</b>, <b>Warn</b> or <b>Debug</b>. (Case insensitive).</td>
    </tr>
    <tr>
    <td>--StdOutput</td>
    <td></td>
    <td>Redirected stdout filename.
        If named <b>auto</b> then file is created inside <b>LogPath</b> with the
        name <b>service-stdout.YEAR-MONTH-DAY.log</b>.</td>
    </tr>
    <tr>
    <td>--StdError</td>
    <td></td>
    <td>Redirected stderr filename.
        If named <b>auto</b> then file is created inside <b>LogPath</b> with the
        name <b>service-stderr.YEAR-MONTH-DAY.log</b>.</td>
    </tr>
    <tr>
    <td>--PidFile</td>
    <td></td>
    <td>Defines the file name for storing the running process id. Actual file is
        created in the <b>LogPath</b> directory</td>
    </tr>
    </table>

</div><h3 id="Installing_services">Installing services</h3><div class="text">
<p>
The safest way to manually install the service is to use the provided
<b>service.bat</b> script. Administrator privileges are required to run this
script. If necessary, you can use the <code>/user</code> switch to specify
a user to use for the installation of the service.
</p>
<p>
<strong>NOTE:</strong> On Windows Vista or any later operating system with User
Account Control (UAC) enabled you will be asked for additional privileges
when 'Tomcat8.exe' is launched by the script.<br>
If you want to pass additional options to service installer as
<code>PR_*</code> environment variables, you have to either configure them
globally in OS, or launch the program that sets them with elevated privileges
(e.g. right-click on cmd.exe and select "Run as administrator"; on Windows 8
(or later) or Windows Server 2012 (or later), you can open an elevated command
prompt for the current directory from the Explorer
by clicking on the "File" menu bar). See issue <a href="http://bz.apache.org/bugzilla/show_bug.cgi?id=56143">56143</a> for details.
</p>

<div class="codeBox"><pre><code>Install the service named 'Tomcat8'
C:\&gt; service.bat install</code></pre></div>

<p>There is a 2nd optional parameter that lets you specify the name of the
service, as displayed in Windows services.</p>

<div class="codeBox"><pre><code>Install the service named 'MyService'
C:\&gt; service.bat install MyService</code></pre></div>

<p>
If using tomcat8.exe, you need to use the <b>//IS//</b> parameter.</p>

<div class="codeBox"><pre><code>Install the service named 'Tomcat8'
C:\&gt; tomcat8 //IS//Tomcat8 --DisplayName="Apache Tomcat 8" ^
     --Install="C:\Program Files\Tomcat\bin\tomcat8.exe" --Jvm=auto ^
     --StartMode=jvm --StopMode=jvm ^
     --StartClass=org.apache.catalina.startup.Bootstrap --StartParams=start ^
     --StopClass=org.apache.catalina.startup.Bootstrap --StopParams=stop</code></pre></div>

</div><h3 id="Updating_services">Updating services</h3><div class="text">
<p>
To update the service parameters, you need to use the <b>//US//</b> parameter.
</p>

<div class="codeBox"><pre><code>Update the service named 'Tomcat8'
C:\&gt; tomcat8 //US//Tomcat8 --Description="Apache Tomcat Server - http://tomcat.apache.org/ " ^
     --Startup=auto --Classpath=%JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\bin\bootstrap.jar</code></pre></div>

<p>If you gave the service an optional name, you need to specify it like this:
</p>

<div class="codeBox"><pre><code>Update the service named 'MyService'
C:\&gt; tomcat8 //US//MyService --Description="Apache Tomcat Server - http://tomcat.apache.org/ " ^
     --Startup=auto --Classpath=%JAVA_HOME%\lib\tools.jar;%CATALINA_HOME%\bin\bootstrap.jar</code></pre></div>

</div><h3 id="Removing_services">Removing services</h3><div class="text">
<p>
To remove the service, you need to use the <b>//DS//</b> parameter.<br>
If the service is running it will be stopped and then deleted.</p>

<div class="codeBox"><pre><code>Remove the service named 'Tomcat8'
C:\&gt; tomcat8 //DS//Tomcat8</code></pre></div>

<p>If you gave the service an optional name, you need to specify it like this:
</p>

<div class="codeBox"><pre><code>Remove the service named 'MyService'
C:\&gt; tomcat8 //DS//MyService</code></pre></div>

</div><h3 id="Debugging_services">Debugging services</h3><div class="text">
<p>
To run the service in console mode, you need to use the <b>//TS//</b> parameter.
The service shutdown can be initiated by pressing <b>CTRL+C</b> or
<b>CTRL+BREAK</b>.
If you rename the tomcat8.exe to testservice.exe then you can just execute the
testservice.exe and this command mode will be executed by default.</p>

<div class="codeBox"><pre><code>Run the service named 'Tomcat8' in console mode
C:\&gt; tomcat8 //TS//Tomcat8 [additional arguments]
Or simply execute:
C:\&gt; tomcat8</code></pre></div>

</div><h3 id="Multiple_Instances">Multiple Instances</h3><div class="text">
<p>
Tomcat supports installation of multiple instances. You can have a single
installation of Tomcat with multiple instances running on different IP/port
combinations, or multiple Tomcat versions, each running one or more instances on
different IP/ports.</p>
<p>
Each instance folder will need the following structure:
</p>
<ul>
<li>conf</li>
<li>logs</li>
<li>temp</li>
<li>webapps</li>
<li>work</li>
</ul>
<p>
At a minimum, conf should contain a copy of the following files from
CATALINA_HOME\conf\. Any files not copied and edited, will be picked up by
default from CATALINA_HOME\conf, i.e. CATALINA_BASE\conf files override defaults
from CATALINA_HOME\conf.</p>
<ul>
<li>server.xml</li>
<li>web.xml</li>
</ul>
<p>
You must edit CATALINA_BASE\conf\server.xml to specify a unique IP/port for the
instance to listen on. Find the line that contains
<code>&lt;Connector port="8080" ...</code> and add an address attribute and/or
update the port number so as to specify a unique IP/port combination.</p>
<p>
To install an instance, first set the CATALINA_HOME environment variable to the
name of the Tomcat installation directory. Then create a second environment
variable CATALINA_BASE and point this to the instance folder. Then run "service
install" command specifying a service name.</p>

<div class="codeBox"><pre><code>set CATALINA_HOME=c:\tomcat_8
set CATALINA_BASE=c:\tomcat_8\instances\instance1
service install instance1</code></pre></div>

<p>
To modify the service settings, you can run <b>tomcat8w //ES//instance1</b>.
</p>
<p>
For additional instances, create additional instance folder, update the
CATALINA_BASE environment variable, and run the service install again.</p>

<div class="codeBox"><pre><code>set CATALINA_BASE=c:\tomcat_8\instances\instance2
service install instance2</code></pre></div>

</div><div class="noprint"><h3 id="comments_section">
                  Comments
                </h3><div class="text"><p class="notice"><strong>Notice: </strong>This comments section collects your suggestions
                    on improving documentation for Apache Tomcat.<br><br>
                    If you have trouble and need help, read
                    <a href="http://tomcat.apache.org/findhelp.html">Find Help</a> page
                    and ask your question on the tomcat-users
                    <a href="http://tomcat.apache.org/lists.html">mailing list</a>.
                    Do not ask such questions here. This is not a Q&amp;A section.<br><br>
                    The Apache Comments System is explained <a href="./comments.html">here</a>.
                    Comments may be removed by our moderators if they are either
                    implemented or considered invalid/off-topic.
                  </p><div id="comments_thread"></div></div></div></div></div></div></div><footer><div id="footer">
    Copyright &copy; 1999-2018, The Apache Software Foundation
  </div></footer></div></body></html>